package main

import (
	"fmt"
	"sync"
	"time"
)

// 互斥锁
var wg sync.WaitGroup
var count = 0
var mutex sync.Mutex

func test() {
	mutex.Lock()
	count++
	fmt.Println(count)
	time.Sleep(time.Millisecond)
	mutex.Unlock()
	wg.Done()
}
func main() {

	for i := 0; i < 20; i++ {
		wg.Add(1)
		go test()
	}

	wg.Wait()

}
